<?php
/**
 * Created by PhpStorm.
 * Clerk: Administrator
 * Date: 2018/8/24
 * Time: 10:28
 */

namespace app\api\model;

use think\Db;
use think\Model;

class Goods extends Model {
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    /**
     * 验证柜员
     * @param $token
     * @return array|bool|false|\PDOStatement|string|Model
     */
    public static function getGoodsList($page,$goods='',$size=9){
        if(empty($goods)){
            $data = Db::name('goods')->field('id,name,price,img')->where(['isdelete'=>0])->limit(($page-1)*$size,$size)->select();
        }else{
            $data = Db::name('goods')->field('id,name,price,img')->where('name','like','%'.$goods.'%')->where(['isdelete'=>0])->limit(($page-1)*$size,$size)->select();
        }
        return $data;
    }

    public static function getGoodsRecommendList($page,$size=9){
        $data = Db::name('goods')->field('id,name,price,img')->where(['recommend'=>1,'isdelete'=>0])->limit(($page-1)*$size,$size)->select();
        return $data;
    }

    public static function getGoodsDetail($goods_id){
        $data = Db::name('goods')->field('id,img,name,price,goods_content,offer_price')->where(['id'=>$goods_id])->find();
        return $data;
    }



}